/*
 * Title: WADS
 * Description: Web-based Auto flow Documents System
 * Copyright: 2007
 * Company: CoE
 * @author: Mr.Nattasan Wang-Aphisit
 * @version 1.1
 */

package wads.app;

import java.io.File;
import javax.swing.filechooser.FileFilter;

public class HTMLFilter extends FileFilter {

    private String acceptableExtensions[];
    private String description = null;

    public HTMLFilter(String ext)
    {
        super();
        acceptableExtensions = new String[1];
        acceptableExtensions[0] = ext;
    }

    public HTMLFilter(String ext[], String description)
    {
        super();
        this.description = description;
        acceptableExtensions = ext;
    }

    // Accept all directories and all files with extension specified
    public boolean accept(File f) {
        if (f.isDirectory()) {
            return true;
        }

        String s = f.getName();
        int i = s.lastIndexOf('.');

        if (i > 0 &&  i < s.length() - 1) {
            String extension = s.substring(i+1).toLowerCase();
            for (int j=0; j<acceptableExtensions.length; j++)
            {
                if (acceptableExtensions[j].equals(extension))
                    return true;
                else
                    return false;
            }
        }
        return false;
    }

    // The description of this filter
    public String getDescription() {
        return this.description;
    }

}
